<?

$Result = GridList();
$Result = "aaaaaaa";
//echo "asdasd"; exit;
$nobkt_awal = 'A';
$nobkt_akhir = 'B';

if ($Result) {
		//echo "cccccc"; exit;
        $Header = "Kode Pajak;Kode Lampiran;Kode Status;Kode Dokumen;NPWP Lawan Transaksi;Nama Lawan Transaksi;Kode Cabang;Digit Tahun/Kode Faktur;Nomor Seri FP/PEB/PIB;Tanggal Faktur;Tanggal SSP;Masa Pajak;Tahun Pajak;Pembetulan;DPP;PPN;PPnBM\r\n";
        foreach ($Result as $Row) {

        //if ($Row["npwp"]=='undefined') { die('NPWP = ' .$Row["npwp"].' untuk Debitur ='.$Row["debnam"].'  silakan perbaiki data');}

                foreach ($Row as $Field) {
                        if (!empty($strExcelRow)) $strExcelRow .= ";$Field";
                        else $strExcelRow = "$Field";
                }
                $strOutput .= $strExcelRow."\r\n";
                $strExcelRow="";
        }
        header("Content-type:application/vnd.notepad");
        header("Content-Disposition:filename=ais_tax_electronic.txt");
        print $Header.$strOutput;
}

function GridList() {
        global $DBProcess,$DBConnection, $Rate;
        list($FDay,$FMonth,$FYear) = explode("/",GetParam("fromDate",""));
        list($TDay,$TMonth,$TYear) = explode("/",GetParam("toDate",""));

        //modified by dyah. 23 juli 2009
        $kcpQuery = "SELECT kodecbg_pjk FROM sis_sit.tblprofile WHERE ktrasl = '".GetOfficeID()."'";
        $kodeCabangPajak = $DBConnection->dbc->get_var($kcpQuery);

        $SQL  = "SELECT 'A' as kp,'1' as kl,'1' as ks,if(ifnull(npwp,'')='',2,1) as kd,npwp,debnam,'".$kodeCabangPajak."',
    if(ifnull(npwp,'')='','',substring(year(tglbkt),-2)),if(ifnull(npwp,'')='',vat,RIGHT(vat,8)),
    date_format(tglbkt,'%d/%m/%Y') as tglbkt,'' as m, date_format(tglbkt,'%m') as l,year(tglbkt) as year,'' as z,
    CASE when curr='USD' THEN REPLACE(format(jumlah*10*vatrate,0),',', '') ELSE REPLACE(format(jumlah*10,0),',', '') END as dpp ,
    CASE when curr='USD' THEN REPLACE(format(jumlah*vatrate,0),',', '') ELSE REPLACE(format(jumlah,0),',', '') END as ppn,
    '0' as j ";
        $SQL .= "FROM $DBProcess.view_faktur_no_fix ";
        $SQL .= "WHERE $DBProcess.view_faktur_no_fix.tglbkt>='$FYear-$FMonth-$FDay' AND  $DBProcess.view_faktur_no_fix.tglbkt<='$TYear-$TMonth-$TDay' AND  skada=(SELECT ppn_skada FROM `sis_sit`.`tblprofile`) ";
//die($SQL);
//        $SQL .= "GROUP BY ";
//echo $SQL; exit;
        return $DBConnection->dbc->get_results($SQL, ARRAY_A);
}

?>
